// 面向对象


// 定义构造函数
function Person() {
  this.name = 'zhichao'
  this.sex = 'nan'
}

Person.prototype.say = function (msg) {
  console.log('说话：', msg)
}

Person.yyy = 'sdfdsf'
Person.yyyfun = function() {

  this.yyyfun2()
 
}
Person.yyyfun2 = function() {

    console.log('Person.yyyfun2 ');
    
}
Person.yyyfun()
Person.yyy
console.log('--------------------------');

let p1 = new Person()

p1.say()


class PersonC {
  name = 'zhichao'
  sex = 'nan'

  say(msg) {
    console.log(`个人信息:${this.name}:${this.sex}`)
    console.log('说话：', msg)
  }
}

let pc12 = new PersonC()
console.log(pc1.name)
console.log(pc1.sex)
pc1.say()



class PersonC {
  name
  sex

  constructor(name, sex) {
    // 构造函数接受到值后，对类属性进行初始化
    console.log('new 对象的时候调用')
    this.name = name
    this.sex = sex
  }
  say(msg) {
    console.log(`个人信息:${this.name}:${this.sex}`)
    console.log('说话：', msg)
  }
}

// 初始化对象，调用构造函数 constructor
// 把'zhichao','nan' 传给 构造函数的形参
let pc1 = new PersonC('zhichao', 'nan')
console.log(pc1.name)
console.log(pc1.sex)

let pc2 = new PersonC('cuimengjiao', 'nv')
console.log(pc2.name)
console.log(pc2.sex)

// pc1.say('我是志超')

console.log('----------------------')

let methodName = 'fun110'


class PersonCMult {
  name
  sex
  birthday
  shenfenzheng

  constructor(user) {
    // 构造函数接受到值后，对类属性进行初始化
    // console.log('new 对象的时候调用')
      // 普通赋值语法
      // this.name = user.name
      // this.sex = user.sex
      // this.birthday = user.birthday
      // this.shenfenzheng = user.shenfenzheng

      // 把赋值逻辑改为解构赋值方法
      ({
        name: this._name,
        sex: this.sex,
        birthday: this.birthday,
        shenfenzheng: this.shenfenzheng,
      } = user)
    
  }

}



class PersonCMult {
  name
  sex
  birthday
  shenfenzheng

  constructor(user) {
    // 构造函数接受到值后，对类属性进行初始化
    // console.log('new 对象的时候调用')
      // 普通赋值语法
      // this.name = user.name
      // this.sex = user.sex
      // this.birthday = user.birthday
      // this.shenfenzheng = user.shenfenzheng

      // 把赋值逻辑改为解构赋值方法
      ({
        name: this._name,
        sex: this.sex,
        birthday: this.birthday,
        shenfenzheng: this.shenfenzheng,
      } = user)
    
  }

  // /取值函数（getter）和存值函数（setter） § ⇧
  get name() {
    return this._name + '：通过getter获取'
  }

  set name(value) {
    console.log('调用了setter,初始化值为：'+value);
    
    this._name = value
  }

  say(msg) {
    console.log(`个人信息:${this.name}:${this.sex}`)
    console.log('说话：', msg)
  }


  [methodName]() {
    console.log('调用了动态方法');
    console.log('fun110');
    
  }



}

let userobj1 = {
  name: 'chao00000',
  sex: 'nan',
  birthday: '2002-12-12',
  shenfenzheng: '2343253535422524',
}
let pcm1 = new PersonCMult(userobj1)

console.log(pcm1.name)


pcm1.name = '崔梦娇'


console.log(pcm1.name)


pcm1[methodName]()



// const MyClass77 = class Me {
//   getClassName() {
//     return Me.name;
//   }
// };

// let inst = new MyClass77();
// inst.getClassName() // Me
// // Me.name // ReferenceError: Me is not defined


// 静态方法

class Foo {
  static classMethod() {
    console.log('classMethod是静态方法');
    return 'hello';
  }
}
// 静态方法调用
Foo.classMethod() // 'hello'

// var foo = new Foo();
// foo.classMethod()




class Foo000 {

  static sBar = 'sbar'

  #name = 'zhichao'
  
  sex = 'nan'

  get name (){
    return this.#name
  }

  set name (value){
      this.#name = value
  }


  static bar() {
    // 静态方法bar调用了this.baz，这里的this指的是Foo类，而不是Foo的实例，
    this.baz();
  }
  static baz() {
    console.log('hello000000');
  }
  baz() {
    console.log('world#######'+this.#name);
  }

  bazf00() {
    // 谁调用就是谁
    this.baz()
  }
}

Foo000.bar() // hello
console.log(Foo000.sBar);



let f00 = new Foo000()

console.log('------------');

console.log(f00.bazf00());

console.log('------------');


// f00.baz()

f00.bazf00()

console.log(f00.name);

f00.name = 'cuimengjiao'

console.log(f00.name );




class Foo {
  #a; // 私有属性
  #b; // 私有属性
  constructor(a, b) {
    this.#a = a; //对私有属性赋值， 私有属性只能在类中通过this调用
    this.#b = b;// 对私有属性赋值，私有属性只能在类中通过this调用
  }
  #sum() {
    return this.#a + this.#b; // 私有属性只能在类中通过this调用
  }
  printSum() {
    console.log(this.#sum());  // 私有方法：只能在类中调用
  }
}

let fooObj1 = new Foo('苹果','橘子')

fooObj1.#a 
fooObj1.#sum